package com.java.control.search;

import org.apache.commons.lang.StringUtils;

/**
 * 通讯录人员
 * @author wqf
 * @version  Nov 24, 2011 11:55:45 AM
 */
public class AddressBookSearchCond extends SearchCond{
	
	private Long userId;//
	
	private String userName;
	private String companyName;
	

	public String getCompanyName() {
		return companyName;
	}


	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}


	public ConditionPart getCondition(){
		ConditionPart cp=new ConditionPart();
		StringBuffer searchStr=new StringBuffer(" 1=1");
		
		if(null!=userId){
			searchStr.append(" and user.id=?");
			cp.getParams().add(this.userId);
		}
		if(StringUtils.isNotBlank(userName)){
			searchStr.append(" and userName like ?");
			cp.getParams().add("%"+userName.trim()+"%");
			this.setUserName(userName.trim());
		}
		
		if(StringUtils.isNotBlank(companyName)){
			searchStr.append(" and companyName like ?");
			cp.getParams().add("%"+companyName.trim()+"%");
			this.setCompanyName(companyName.trim());
		}
		
		cp.setExpression(searchStr.toString());
		return cp;
	}


	public String getUserName() {
		return userName;
	}


	public void setUserName(String userName) {
		this.userName = userName;
	}
	public Long getUserId() {
		return userId;
	}


	public void setUserId(Long userId) {
		this.userId = userId;
	}
}
